<?php

namespace App\Models\Library;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;

// 已注册备案的新原料（2021-至今）
class RegisteredMaterials extends Model
{
    use HasFactory;
    use Searchable;

    protected $table = "library_registered_materials";
    protected $primaryKey = "id";

    protected $fillable = [
        'name_zh',
        'name_en',
        'cas',
        'record_num',
        'record_date',
        'purpose',
        'range',
        'maximum_concentration',
        'other_requirements',
        'enterprise',
        'status',
    ];

    /**
     * 指定 搜索索引中存储的唯一ID
     * @return mixed
     */
    public function getScoutKey()
    {
        return $this->id;
    }

    /**
     * 指定 搜索索引中存储的唯一ID的键名
     * @return string
     */
    public function getScoutKeyName()
    {
        return 'id';
    }

    /**
     * Get the name of the index associated with the model.
     *
     * @return string
     */
    public function searchableAs()
    {
        return $this->table;
    }

    public function toSearchableArray()
    {
        return [
            'id' => $this->id,
            'name_zh' => $this->name_zh,
            'name_en' => $this->name_en,
            'cas' => $this->cas,
            'record_num' => $this->record_num,
            'record_date' => $this->record_date,
            'range' => $this->range,
            'purpose' => $this->purpose,
            'maximum_concentration' => $this->maximum_concentration,
            'other_requirements' => $this->other_requirements,
            'enterprise' => $this->enterprise,
            'status' => $this->status,
            'created_at' => $this->created_at,
        ];
    }
}
